/**
 *	Main.js - contains:
 *		- initial app setup functions
 *		- main app navigation function
**/

var Main = {
	
	debug: true,
	
	_pageStyle: 'inline-block',
	
	//init function
	init: function() {
		this._setupAllButtons()
		
		if (this.debug) {
			document.getElementById('LPuser').value = 'testlol'
		}
		
		this.goTo('LoginPage')
		return
		
		//debug - start a game and run locally
		this.goTo('GamePage')
		var g = {
			players: [ 'p1', 'p2' ],
			winner: 0
		}
		this.clientInfo = { user: 'p1' }
		MouseEvents._debug = true
		Game.setUpGame(g)
		Game.draw()
	},
	
	//set up anchor buttons to flash on focus events
	_setupButtonFn: [
		function() { return false },
	],
	_setupAllButtons: function() {
		var a = document.getElementsByTagName('a'),
			regexp = /\s*button\s*/
		
		for (var i=0; i<a.length; i++) {
			if ( a[i].className.match(regexp) ) {
				this.setupButton(a[i])
			}
		}
	},
	
	//setup the anchor as a button
	setupButton: function(btn) {
		btn.onmousedown = this._setupButtonFn[0]
	},
	
	//logic required to go to page
	goTo: function(id) {
		if (typeof this._currentPage !== 'undefined') {
			this._currentPage.style.display = 'none'
		}
		
		this._currentPage = document.getElementById(id)
		this._currentPage.style.display = this._pageStyle
		
		if ( this._goToActions[id] ) {
			this._goToActions[id]()
		}
	},
	
	//special actions to take after goto
	_goToActions: {
		GamePage: function() {
			Game.init()
		}
	}
	
}